<template>
  <div class="wrapper">
    <header class="main-header">
      <a href="/" class="logo">
        <!-- mini logo for sidebar mini 40x50 pixels -->
        <span class="logo-mini"><img src="/static/img/logo_sm.png" alt="Logo"
                                     class="img-responsive center-block"></span>
        <!-- logo for regular state and mobile devices -->
        <div class="container logo-lg">
          <div class="pull-left image"><img src="/static/img/logo_sm.png" alt="Logo" class="img-responsive"></div>
          <div class="pull-left info">用为医疗</div>
        </div>
      </a>

      <!-- Header Navbar -->
      <nav class="navbar navbar-static-top" role="navigation">
        <!-- Sidebar toggle button-->
        <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
          <span class="sr-only">Toggle navigation</span>
        </a>
        <!-- Navbar Right Menu -->
        <div class="navbar-custom-menu">
          <ul class="nav navbar-nav">
            <!-- Messages-->
            <li class="dropdown messages-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-envelope-o"></i>
                <span class="label label-success">{{ state.userInfo.messages | count }}</span>
              </a>
              <ul class="dropdown-menu">
                <li class="header">You have {{ state.userInfo.messages | count }} messages</li>
                <li>
                  <!-- inner menu: contains the messages -->
                  <ul class="menu">
                    <li><!-- start message -->
                      <a href="#">
                        <!-- Message title and timestamp -->
                        <h4>
                          Support Team
                          <small><i class="fa fa-clock-o"></i> 5 mins</small>
                        </h4>
                        <!-- The message -->
                        <p>Why not buy a new awesome theme?</p>
                      </a>
                    </li>
                    <!-- end message -->
                  </ul>
                  <!-- /.menu -->
                </li>
                <li class="footer"><a href="#">See All Messages</a></li>
              </ul>
            </li>
            <!-- /.messages-menu -->

            <!-- Notifications Menu -->
            <li class="dropdown notifications-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-bell-o"></i>
                <span class="label label-warning">{{ state.userInfo.notifications | count }}</span>
              </a>
              <ul class="dropdown-menu">
                <li class="header">You have {{ state.userInfo.notifications | count }} notifications</li>
                <li>
                  <!-- Inner Menu: contains the notifications -->
                  <ul class="menu">
                    <li><!-- start notification -->
                      <a href="#">
                        <i class="fa fa-users text-aqua"></i> 5 new members joined today
                      </a>
                    </li>
                    <!-- end notification -->
                  </ul>
                </li>
                <li class="footer"><a href="#">View all</a></li>
              </ul>
            </li>

            <!-- Tasks Menu -->
            <li class="dropdown tasks-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-flag-o"></i>
                <span class="label label-danger">{{ state.userInfo.tasks | count }} </span>
              </a>
              <ul class="dropdown-menu">
                <li class="header">You have {{ state.userInfo.tasks | count }} tasks</li>
                <li>
                  <!-- Inner menu: contains the tasks -->
                  <ul class="menu">
                    <li><!-- Task item -->
                      <a href="#">
                        <!-- Task title and progress text -->
                        <h3>
                          Design some buttons
                          <small class="pull-right">20%</small>
                        </h3>
                        <!-- The progress bar -->
                        <div class="progress xs">
                          <!-- Change the css width attribute to simulate progress -->
                          <div class="progress-bar progress-bar-aqua" style="width: 20%" role="progressbar"
                               aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only">20% Complete</span>
                          </div>
                        </div>
                      </a>
                    </li>
                    <!-- end task item -->
                  </ul>
                </li>
                <li class="footer">
                  <a href="#">View all tasks</a>
                </li>
              </ul>
            </li>

            <!-- User Account Menu -->
            <li class="dropdown user user-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <!-- The user image in the navbar-->
                <img v-bind:src=demo.avatar class="user-image" alt="User Image">
                <!-- hidden-xs hides the username on small devices so only the image appears. -->
                <span class="hidden-xs" v-if="demo.displayName!=null">{{ demo.displayName }}</span>
                <span class="hidden-xs" v-if="demo.displayName==null">您好，游客</span>
              </a>
              <ul class="dropdown-menu" v-if="demo.displayName!=null">
                <li class="header">You have {{ state.userInfo.notifications | count }} notifications</li>
                <li>
                  <!-- Inner Menu: contains the notifications -->
                  <ul class="menu">
                    <li><!-- start notification -->
                      <a href="#">
                        我的账户
                      </a>
                    </li>
                    <!-- end notification -->
                  </ul>
                  <ul class="menu">
                    <li><!-- start notification -->
                      <a href="/" v-on:click="onDestroy()">
                        退出当前账户
                      </a>
                    </li>
                    <!-- end notification -->
                  </ul>
                </li>
              </ul>

              <ul class="dropdown-menu" v-if="demo.displayName==null">
                <li>
                  <ul class="menu">
                    <li><!-- start notification -->
                      <a href="login">
                        登录
                      </a>
                    </li>
                  </ul>
                </li>
              </ul>
            </li>
          </ul>
        </div>
      </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">

      <!-- sidebar: style can be found in sidebar.less -->
      <section class="sidebar">

        <!-- Sidebar user panel (optional) -->
        <div class="user-panel">
          <div class="pull-left image">

          </div>
          <div class="pull-left info">
            <div><p class="white">{{ demo.displayName }}</p></div>
            <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
          </div>
        </div>

        <!-- search form (Optional) -->
        <form v-on:submit.prevent class="sidebar-form">
          <div class="input-group">
            <input type="text" name="search" id="search" class="search form-control" data-toggle="hideseek"
                   placeholder="Search Menus" data-list=".sidebar-menu">
                <span class="input-group-btn">
                  <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
                  </button>
                </span>
          </div>
        </form>
        <!-- /.search form -->
        <!-- Sidebar Menu -->
        <ul class="sidebar-menu">
          <li class="header">TOOLS</li>
          <li class="active pageLink" v-on:click="toggleMenu"><a v-link="{path: '/'}"><i class="fa fa-desktop"></i><span
            class="page">Dashboard</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/tables'}"><i class="fa fa-table"></i><span
            class="page">Tables</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/task'}" v-if="demo.displayName!=null"><i
            class="fa fa-table"></i><span
            class="page">工作管理</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/login'}" v-if="demo.displayName==null"><i
            class="fa fa-table"></i><span
            class="page">工作管理</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/node'}" v-if="demo.displayName!=null"><i
            class="fa fa-file"></i><span
            class="page">文件列表</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/login'}" v-if="demo.displayName==null"><i
            class="fa fa-file"></i><span
            class="page">文件列表</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/member'}" v-if="demo.displayName!=null"><i
            class="fa fa-user"></i><span
            class="page">人员管理</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/login'}" v-if="demo.displayName==null"><i
            class="fa fa-user"></i><span
            class="page">人员管理</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/wiki'}" v-if="demo.displayName!=null"><i
            class="fa fa-file"></i><span
            class="page">Wiki管理</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/login'}" v-if="demo.displayName==null"><i
            class="fa fa-file"></i><span
            class="page">Wiki管理</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/report'}"><i class="fa fa-user"></i><span
            class="page">检查报告</span></a></li>

          <li class="header">ME</li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/tasks'}"><i class="fa fa-tasks"></i><span
            class="page">Tasks</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/setting'}"><i class="fa fa-cog"></i><span
            class="page">Settings</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/testwiki'}"><i class="fa fa-tasks"></i><span
            class="page">Test</span></a></li>

          <li class="header">LOGS</li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/access'}"><i class="fa fa-book"></i><span
            class="page">Access</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/server'}"><i class="fa fa-hdd-o"></i><span
            class="page">Server</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/repos'}"><i class="fa fa-heart"></i><span
            class="page">Repos</span>
            <small class="label pull-right bg-green">AJAX</small>
          </a></li>
          <li class="header">PAGES</li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/login'}"><i
            class="fa fa-circle-o text-yellow"></i> <span class="page">Login</span></a></li>
          <li class="pageLink" v-on:click="toggleMenu"><a v-link="{path: '/404'}"><i
            class="fa fa-circle-o text-red"></i> <span class="page">404</span></a></li>
        </ul>
        <!-- /.sidebar-menu -->
      </section>
      <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          {{$route.name | uppercase }}
          <small>{{ $route.description }}</small>
        </h1>
        <ol class="breadcrumb">
          <li><a href="#"><i class="fa fa-home"></i>Home</a></li>
          <li class="active">{{$route.name | uppercase }}</li>
        </ol>
      </section>
      <router-view></router-view>
    </div>
    <!-- /.content-wrapper -->
    <!-- Main Footer -->
    <footer class="main-footer">
      <strong>Copyright &copy; {{year}} <a href="#">CoPilot</a>.</strong> All rights reserved.
    </footer>
  </div>
  <!-- ./wrapper -->
</template>

<script>
  import faker from 'faker'
  require('hideseek')

  module.exports = {
    name: 'Dash',
    data: function () {
      return {
        section: 'Dash',
        me: '',
        error: '',
        api: {
          servers: {
            url: '', // Back end server
            result: []
          }
        }
      }
    },
    computed: {
      store: function () {
        return this.$parent.$store
      },
      state: function () {
        return this.store.state
      },
      callAPI: function () {
        return this.$parent.callAPI
      },
      demo: function () {
        return {
          // displayName: faker.name.findName(),
          displayName: window.localStorage.getItem('Username'),
          avatar: faker.image.avatar(),
          email: faker.internet.email(),
          randomCard: faker.helpers.createCard(),
          status: window.localStorage.getItem('Token')
        }
      }
    },
    methods: {
      changeloading: function () {
        this.store.dispatch('TOGGLE_SEARCHING')
      },
      toggleMenu: function (event) {
        // remove active from li
        window.$('li.pageLink').removeClass('active')
        // Add it to the item that was clicked
        event.toElement.parentElement.className = 'pageLink active'
      },
      onDestroy: function () {
        window.localStorage.clear()
        this.$store.dispatch('SET_TOKEN', null)
      }
    },
    ready: function () {
      // Page is ready. Let's load our functions!
    }
  }
</script>

<style>
  .user-panel {
    height: 4em;
  }
</style>
